package com.mzz.structure.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xushijian
 * @date 18/6/8 上午9:12
 */
public class Composite extends Component {

    private List<Component> child = new ArrayList();

    public Composite(String name) {
        super(name);
    }

    @Override
    void add(Component component) {

        child.add(component);

    }

    @Override
    void remove(Component component) {
        child.remove(component);
    }

    @Override
    void foreach() {
        System.out.println("节点名：\t" + name);

        for (Component c : child) {
            c.foreach();
        }
    }
}
